//
//  CVCellOfTopicTwo.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/13.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "CVCellOfTopicTwo.h"
#import "BaseTableView.h"
#import "MJMacro.h"
#import "TVCellOfSecondTopic.h"
#import "RootClassOfNewTopic.h"
#import "DataOfNewTopic.h"
#import "CategoryOfDataNewTopic.h"
#import "UserOfDataNewTopic.h"
#import "BaseOfDataNewTopicOfUserDataNewTopic.h"
#import "TeacherOfUserDataNewTopic.h"
#import "Way_Type_SetOfTeacherUserDataNewTopic.h"
#import "ZWYNetTool.h"
#import "UIImageView+WebCache.h"
@interface CVCellOfTopicTwo()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) RootClassOfNewTopic *rootClassOfNewTopic;
@property (nonatomic, strong) BaseTableView *tableViewOfTopic;
@end
@implementation CVCellOfTopicTwo
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        // 创建 TableView
        [self createTableView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // 创建 TableView
        [self createTableView];
        [self handleData];
    }
    return self;
}
#pragma mark - 数据解析
- (void)handleData{
    [ZWYNetTool GET:@"http://yiapi.xinli001.com/v2/yi/teacher-topic-list.json?key=18ee0593a01c07f71d28fa936d671457&_platform=ios&_version=4.0&flag=new" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
//        NSLog(@"%@", result);
        _rootClassOfNewTopic = [RootClassOfNewTopic modelDic:result];
        [_tableViewOfTopic reloadData];
    } andFailureBlock:^(NSError *error) {
        
    }];
}
#pragma mark - 创建 TableView
- (void)createTableView{
    self.tableViewOfTopic = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
//    self.tableViewOfTopic.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];
    [self.contentView addSubview:_tableViewOfTopic];
    self.tableViewOfTopic.delegate = self;
    self.tableViewOfTopic.dataSource = self;
    [self.tableViewOfTopic registerNib:[UINib nibWithNibName:@"TVCellOfSecondTopic" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"TVCellOfSecondTopic"];
    
}
#pragma mark - tableView 代理方法 row 数量的确定
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _rootClassOfNewTopic.data.count;
}
#pragma mark - tableView 代理方法 row 高度的确定
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 300;;
}
#pragma mark - tableView 代理方法 cell 的赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TVCellOfSecondTopic *cell = [tableView dequeueReusableCellWithIdentifier:@"TVCellOfSecondTopic" forIndexPath:indexPath];
    [cell.avatarIamgeView sd_setImageWithURL:[NSURL URLWithString:_rootClassOfNewTopic.data[indexPath.row].user.avatar] placeholderImage:[UIImage imageNamed:@"0"]];
    cell.avatarIamgeView.layer.cornerRadius = 30;
    cell.avatarIamgeView.clipsToBounds = YES;
    cell.nicknameLabel.text = _rootClassOfNewTopic.data[indexPath.row].user.nickname;
    cell.honorLabel.text = _rootClassOfNewTopic.data[indexPath.row].user.teacher.honor;
    cell.titleLabel.text = _rootClassOfNewTopic.data[indexPath.row].title;
    cell.descriptionLabel.text = _rootClassOfNewTopic.data[indexPath.row].myDescription;
    cell.zixunnumLabel.text = [NSString stringWithFormat:@"%@人咨询过", _rootClassOfNewTopic.data[indexPath.row].user.teacher.zixunnum];
    return cell;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
